package com.hsl.housaileibot001.ai;

import com.hsl.housaileibot001.ai.service.AiChatService;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.rag.content.retriever.ContentRetriever;
import dev.langchain4j.service.AiServices;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Date 2025/10/18 14:31
 * @Author hsl
 */
// @Configuration
@ConditionalOnProperty(name = "ai.provider", havingValue = "qwen")
public class AiServiceFactory {
    @Resource
    // private ChatModel qwenChatModel2;
    private ChatModel qwenChatModel;
    @Resource
    private ContentRetriever contentRetriever;
    // @Resource
    // private McpToolProvider mcpToolProvider;
    @Resource
    private StreamingChatModel streamingChatModel;

    @Bean
    public AiChatService aiChatService() {
        // ! 会话记忆
        // MessageWindowChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);
        return AiServices.builder(AiChatService.class)
                // .chatMemory(chatMemory)
                .streamingChatModel(streamingChatModel)
                .chatMemoryProvider(memoryId -> MessageWindowChatMemory.withMaxMessages(10))
                .chatModel(qwenChatModel)
                // .contentRetriever(contentRetriever) // RAG 检索增强
                // .tools(new InterviewQuestionTool()) // 工具调用
                // .toolProvider(mcpToolProvider)      // MCP 工具调用
                .build();
    }
}
